package net.kts.help;

import net.kts.main.R;
import net.kts.transrate.TranslateService;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

public class HelpLayout implements Help{
	private int drawable;
	private Help help;
	private boolean isClick;
	
    public HelpLayout(int drawable) {
    	this.drawable = drawable;
	}
    @Override
	public Help add(final Activity activity, final Animation in, final Animation out) {
		LayoutInflater inflater = activity.getLayoutInflater();
		final View helpView = (View) inflater.inflate(R.layout.help_main, null);
		helpView.setBackgroundDrawable(activity.getResources().getDrawable(drawable));
		activity.addContentView(helpView, new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.FILL_PARENT));
		helpView.startAnimation(in);
		helpView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(help != null)
					help.add(activity, in, out);
				if(isClick == true){
					helpView.setVisibility(helpView.INVISIBLE);	
					return;
				}
				isClick = true;
				helpView.setVisibility(helpView.INVISIBLE);
				helpView.startAnimation(out);
			}
		});
		
		ImageButton close= (ImageButton) helpView.findViewById(R.id.help_close);
		close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				helpView.setVisibility(helpView.INVISIBLE);
				helpView.startAnimation(out);
				HelpPreferences.off();
				Toast.makeText(v.getContext(), TranslateService.translateRepository("도움말 끄기"), Toast.LENGTH_SHORT).show();				
			}
		});
		return this;
	}
	@Override
	public Help addHelpLayout(Help help) {
		this.help = help;
		return help;
	}		
}
